<? if (! empty($products)): ?>
<?php

    if (empty($imageSize)) {
        $imageSize = array(120, 120);
    }
    if (! is_array($imageSize)) {
        $imageSize = array($imageSize, $imageSize);
    }
    
    if (empty($maxName)) {
        $maxName = 15;
    }
    
    $hideWight = !!@$hideWeight;
    
    $format              = "width:%dpx;height:%dpx;";
    $cssDimensions       = sprintf($format, $imageSize[0], $imageSize[1]);
    $cssDimensionsOffset = sprintf($format, $imageSize[0]+4, $imageSize[1]+4);

?>
<ul class="product-list">
    <? foreach($products as $product): ?>
    <?php
        $productId   = $product['Product']['id'];
        $productName = $product['Product']['name'];
        $productImg  = @$product['ProductImage'][0]['src'];
        $productLink = "/products/view/{$groupKey}/{$productId}/" . urlize($productName);
        
        $details = Set::combine($product['ProductDetail'], '{n}.name', '{n}.value');
        $productPrice = 0;
        foreach ($details as $k=>$v) {
            if (strtolower($k) == 'cena') {
                $productPrice = (float)$v;
                break;
            }
        }
    ?>
    <li style="<?= $cssDimensions ?>">
        <?= $this->Html->link(
            $this->Html->image("products/{$productId}/{$productImg}?w=".$imageSize[0]."&h=".$imageSize[1]),
            $productLink, array(
                'escape' => false,
                'style'  => $cssDimensions
        )) ?>
        <a href="<?= $productLink ?>" class="info" style="<?= $cssDimensionsOffset ?>">
            <span class="line">
                <?= (count($productName)>$maxName ? substr($productName, 0, $maxName)."..." : $productName) ?>
            </span>
        </a>
        <div class="price"><?= currency_format($productPrice, true) ?></div>
    </li>
    <? endforeach ?>
</ul>
<? endif ?>